package edu.fh.salzburg.its.opsystems.newfs.definition;

import java.io.File;
import java.util.List;

import edu.fh.salzburg.its.opsystems.newfs.exception.NewFSException;


/**
 * 
 * @author Michael Brachtl mbrachtl.lba@fh-salzburg.ac.at
 *
 */
public interface NewFS {

	/**
	 * We take an old 1,44 MB Floppy - exact size is :
	 * 80 Tracks, 18 Sectors, 512 Byte per sector, 2 Sides
	 * = 80 * 18 * 512 * 2
	 */
	public static int STORAGE_SIZE_IN_BYTES = 1474560;
	
	/**
	 * This should resemble the POSIX write call. The returned value should indicate a  
	 * performance impact (non consecutive blocks written etc..)
	 * 
	 * @param file
	 * @param data
	 * @return - time operation took (ms, (or any time unit))
	 * @throws - NewFSException if something goes wrong
	 */
	public int write(NewFSFile file, Byte[] data) throws NewFSException;
	
	/**
	 * This should resemble the POSIX read call, but we always read the file at once.
	 * @param file the file to read via  its file identifier
	 * @return The contents of the file in a byte array
	 * @throws - NewFSException if something goes wrong
	 */
	public Byte[] read(NewFSFile file) throws NewFSException;
	
	/**
	 * As a minimum, the filesystem should have directories.
	 * This call should list the content of the directory 
	 * @param directory
	 * @return 
	 * @throws - NewFSException if something goes wrong
	 */
	public List<NewFSElement> getDirectoryContents (NewFSDirectory directory) throws NewFSException;
	
	/**
	 * Will create a directory with teh given directory information
	 * @param directory to be deleted (using identifier)
	 * @throws - NewFSException if something goes wrong
	 */
	public void createDirectory (NewFSDirectory directory) throws NewFSException;
	
	/**
	 * Will delete a directory with the given directory information
	 * @param directory to be deleted (using identifier)
	 * @throws - NewFSException if something goes wrong
	 */
	public void deleteDirectory (NewFSDirectory directory) throws NewFSException;
	
	/**
	 * Will delete a file with the given file information
	 * @param file the file to be deleted (using identifier)
	 * @throws NewFSException if something goes wrong
	 */
	public void deleteFile (NewFSFile file) throws NewFSException;
	
	
	/**
	 * Gives a list of Attributes of the element. String list, just to print out. 
	 * @param element the element of the filesystem
	 * @return list of attributes in string format
	 * @throws NewFSException if something goes wrong
	 */
	public List<String> getAttributes (NewFSElement element) throws NewFSException;
	
	
	/**
	 * This will overwrite the given byteAdress number with zeros - see how your FS reacts 
	 * @param byteAdress - from 0 to STORAGE_SIZE_IN_BYTES
	 * @throws NewFSException if something goes wrong
	 */
	public void destroy(int byteAdress) throws NewFSException;
	
	/**
	 * The complete content of the current filesystem should be written to disk.
	 * So it will survive a restart and can later be restored via the initializeFromFile call
	 * @param realFileOnDisk - the real JVM file
	 * @throws - NewFSException if something goes wrong
	 */
	public void writeFsToRealFile(File realFileOnDisk) throws NewFSException;
	
	
	/**
	 * File system is restored from this file
	 * @param realFileOnDisk - the real JVM file
	 * @throws - NewFSException if something goes wrong
	 */
	public void initializeFromFile(File realFileOnDisk) throws NewFSException;
	
	/**
	 * This resembles a chkfsk call - it should check the filesystem an return 
	 * a summary of the status in human readable form.
	 * It should contain: 
	 * bytes free, 
	 * bytes used by metainformation, 
	 * number of files,
	 * number of directories
	 * everything ok?
	 * your additional status (fragementation, number of different users, etc..)  
	 * @return a status of the filesystem
	 * @throws - NewFSException if something goes wrong
	 */
	public List<String> checkFilesystem() throws NewFSException;
	
}
